import { request } from '@umijs/max';
// type QueryData = {
//   name?: string;
// };

/**
 * 获取列表数据
 * @returns
 */
//  QueryData & { pageSize: number; current: number }
export const loadDataAPI = async (params: any) => {
  // console.log(params);
  const res = await request('/admin/article_categories', {
    method: 'GET',
    params: {
      name: params.name, // 查询条件
      per: params.pageSize, // 每页显示的刷量
      page: params.current, // 页码
    },
  });
  // console.log(res);
  return {
    data: res.data.list, // 数据
    // success 请返回 true，
    // 不然 table 会停止解析数据，即使有数据
    success: true,
    // 不传会使用 data 的长度，如果是分页一定要传
    total: res.data.total,
  };
};

/**
 * 获取100条数据
 * @returns
 */
export const loadAllDataAPI = () => {
  return request('/admin/article_categories', {
    method: 'GET',
    params: {
      per: 100,
    },
  });
};

/**
 * 新增
 * @param data
 * @returns
 */
export const createOneAPI = (data: any) => {
  return request('/admin/article_categories', {
    method: 'POST',
    data,
  });
};

/**
 * 根据id修改
 * @param id
 * @param data
 * @returns
 */
export const updateByIdAPI = (id: string, data: any) => {
  return request('/admin/article_categories/' + id, {
    method: 'PATCH',
    data,
  });
};

/**
 * 根据id删除
 * @param id
 * @returns
 */
export const delByIdAPI = (id: string) => {
  return request('/admin/article_categories/' + id, {
    method: 'DELETE',
  });
};

/**
 * 根据id获取单个数据
 * @param id
 * @returns
 */
export const loadDataById = (id: string) => {
  return request('/admin/article_categories/' + id, {
    method: 'GET',
  });
};

/**
 * 删除多个
 * @param ids 用,分割的数据
 * @returns
 */
export const deleteManyAPI = (ids: string) => {
  return request('/admin/article_categories/remove_many?ids=' + ids, {
    method: 'DELETE',
  });
};
